package com.yihu.wlyy.repository;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.yihu.wlyy.entity.doctor.DoctorTeam;

public interface DoctorTeamDao extends
PagingAndSortingRepository<DoctorTeam, Long>,
JpaSpecificationExecutor<DoctorTeam> {

	DoctorTeam findByCode(String code);

	@Query("select dt from DoctorTeam dt,DrHealthTeamMember dtm  where dt.code=dtm.team and dt.del=1 and dtm.del=1 and dtm.memberCode= ?1 and dtm.type= 5 and dtm.signType='2'")
	DoctorTeam findByParientCode(String parientCode);

	@Query("select dt from DoctorTeam dt,DrHealthTeamMember dtm  where dt.code=dtm.team and dt.del=1 and dtm.del=1 and dtm.memberCode= ?1 and dtm.type= 5 and dtm.signType='1'")
	DoctorTeam findBySanshiParientCode(String parientCode);

	@Query("select dt from DoctorTeam dt,DrHealthTeamMember dtm  where dt.code=dtm.team and dt.del=1 and dtm.del=1 and dtm.memberCode= ?1 and dtm.type= 5 and dtm.signType=?2")
	DoctorTeam findByParientCodeAndSignType(String parientCode,String type);

	@Modifying
	@Query("update DoctorTeam a set a.del =0  where a.code = ?1 and signType='2'")
	void deleteTeam(String teamCode);
}
